<?php
/**
 * Static content controller.
 *
 * This file will render views from views/pages/
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class CategorysController extends AppController {

	public $uses = array('News', 'Category');
	/**
	 * Components
	 * @var array
	 */
	public $components = array(
		'Paginator',
		'ConstAdmin',
		'Common',
	);

	public function beforeFilter() {
		parent::beforeFilter();
		$title_for_layout = 'Danh muc - Ngân hàng 24h';
		$this->set(compact('page', 'subpage', 'title_for_layout'));
	}
/**
 * Displays a view
 *
 * @param mixed What page to display
 * @return void
 * @throws NotFoundException When the view file could not be found
 *	or MissingViewException in debug mode.
 */
	public function index($cat_rewrite) {
		$sercuritySalt = Configure::read('Security.salt');
		$cat_rewrite = md5(md5($cat_rewrite).$sercuritySalt);
		$category = $this->Category->getCategoryId($cat_rewrite);
		$conditions = array(
				'active' => 1,
				'del_flg' => 0,
				'category_id' => $category['list_id'],
		);
		$paginate = array(
				'fields' => '*',
				'limit' => ConstAdminComponent::PAGE_NUMBER_LIMIT,
				'conditions' => $conditions,
				'order' => array(
					'last_update' => 'DESC',
				),
		);

		$this->Paginator->settings = $paginate;
		$listNews = $this->Paginator->paginate('News');

		$title_for_layout = $category['category']['categories_multi']['cat_name'];
		$keywords_for_layout = $category['category']['categories_multi']['cat_keyword'];
		$description_for_layout = $category['category']['categories_multi']['cat_description'];
		$this->set(
			array(
				'cat_name' => $category['category']['categories_multi']['cat_name'],
				'cat_rewrite' => $this->request->params['cat_rewrite'],
				'list_news' => $listNews,
				'page_number_limit' => ConstAdminComponent::PAGE_NUMBER_LIMIT,
				'title_for_layout' => $title_for_layout,
				'keywords_for_layout' => $keywords_for_layout,
				'description_for_layout' => $description_for_layout,
			)
		);
	}

}
